﻿using MediatR;
using T.Materials.Domain.Model;
using T.Materials.Read.API.ApplicationRead.Command.MaterialStatisticsCommand;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.Read.API.ApplicationRead.CommandHandler.MaterialStatisticsCommandHandler
{
    /// <summary>
    /// 反填物资统计命令处理器
    /// </summary>
    public class ReverseMaterialStatisticsCommandHandler : IRequestHandler<ReverseMaterialStatisticsCommand, MaterialStatistics>
    {
        /// <summary>
        /// 物资统计仓储接口
        /// </summary>
        protected readonly IMaterialStatisticsRepository materialStatisticsRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialStatisticsRepository">物资统计仓储接口</param>
        public ReverseMaterialStatisticsCommandHandler(IMaterialStatisticsRepository materialStatisticsRepository)
        {
            this.materialStatisticsRepository = materialStatisticsRepository;
        }

        /// <summary>
        /// 处理反填物资统计命令
        /// </summary>
        /// <param name="request">反填物资统计命令</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回物资统计实体</returns>
        public async Task<MaterialStatistics> Handle(ReverseMaterialStatisticsCommand request, CancellationToken cancellationToken)
        {
            return await materialStatisticsRepository.GetModelAsync(request.MaterialStatisticsId);
        }
    }
}
